/*定义一个复数类Complex，默认初始化为0，
重载运算符“＋”，“－”，使之能用于复数的加，减运算，
运算符重载函数作为Complex类的成员函数。编程序，
分别求出两个复数之和，差。（
复数的输出格式比如：3+2i）【3分：复数的定义，默认初始化1分，
运算符的重载1分，主函数测试，能正确输出两个复数运算的结果1分】*/
#include <iostream>
using namespace std;
class Complex
{
private:
    int shi;
    int xu;
public:
    //构造
    Complex(int shi=0,int xu=0)
    :shi(shi),xu(xu)
    {
    }
    //析构
    ~Complex()
    {
    }
    //显示
    void display()const
    {
        if(this->xu == 0)
        {
            cout<<this->shi;
        }
        else
        {
            cout<<this->shi<<"+"<<this->xu<<"i";
        }
        
    }
    //实部
    int getShi()const
    {
        return this->shi;
    }
    //虚部
    int getXu()const
    {
        return this->xu;
    }
};
//+
Complex operator + (const Complex&co1,const Complex&co2 )
{
    int shi = co1.getShi() + co2.getShi();
    int xu  = co1.getXu() + co2.getXu();
    return Complex(shi,xu);
}
//-
Complex operator - (const Complex&co1,const Complex&co2 )
{
    int shi = co1.getShi() - co2.getShi();
    int xu  = co1.getXu() - co2.getXu();
    return Complex(shi,xu);
}

int main(int argc,char*argv[])
{
    Complex co1(3,3);
    Complex co2(2,2);

    Complex co3 = co1 + co2;
    cout<<"(";
    co1.display();
    cout<<")";
    cout<<"+";    
    cout<<"(";
    co2.display();
    cout<<")";
    cout<<"=";
    co3.display();
    cout<<endl;

    Complex co4 = co1 - co2;
    cout<<"(";
    co1.display();
    cout<<")";
    cout<<"-";    
    cout<<"(";
    co2.display();
    cout<<")";
    cout<<"=";
    co4.display();
    cout<<endl;
    return 0;
}